﻿import QtQuick 2.15
import QtQuick.Window 2.15

Window {
    width: 1100
    height: 600
    minimumWidth: 1100
    maximumWidth: 1100
    minimumHeight: 600
    maximumHeight: 600
    visible: true
    title: qsTr("解密工具")

    Item{
        id:backGround
        anchors.fill: parent
    }

    property string dateText

    property string timeText

    Component.onCompleted: {
        dateText = Qt.formatDateTime(new Date(),"yyyy-MM-dd")
        timeText = Qt.formatDateTime(new Date(),"hh:mm:ss")
    }

    Timer{
        running: true
        interval: 1000
        repeat: true
        onTriggered: {
            dateText = Qt.formatDateTime(new Date(),"yyyy-MM-dd")
            timeText = Qt.formatDateTime(new Date(),"hh:mm:ss")
        }
    }

    Text{
        anchors.horizontalCenter: backGround.horizontalCenter
        anchors.top: backGround.top
        anchors.topMargin: 10
        horizontalAlignment: Text.horizontalAlignment
        font.pixelSize: 50
        text:"麦青智能-解密工具"
    }

    Text{
        anchors.left: backGround.left
        anchors.leftMargin: 20
        anchors.top: backGround.top
        anchors.topMargin: 10
        font.pixelSize: 40
        text:dateText
    }
    Text{
        anchors.right: backGround.right
        anchors.rightMargin: 20
        anchors.top: backGround.top
        anchors.topMargin: 10
        font.pixelSize: 40
        text:timeText
    }

    Rectangle{
        anchors.top: backGround.top
        anchors.topMargin: 100
        width: backGround.width
        height: 5
        color: "black"
    }



    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 20
        anchors.top: backGround.top
        anchors.topMargin: 120
        width: 200
        height: 100
        border.width: 1

        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            text: qsTr("年")
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 230
        anchors.top: backGround.top
        anchors.topMargin: 120
        width: 200
        height: 100
        border.width: 1
        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            text: qsTr("月")
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 440
        anchors.top: backGround.top
        anchors.topMargin: 120
        width: 200
        height: 100
        border.width: 1
        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            text: qsTr("日")
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 650
        anchors.top: backGround.top
        anchors.topMargin: 120
        width: 200
        height: 100
        border.width: 1
        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            text: qsTr("时")
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 860
        anchors.top: backGround.top
        anchors.topMargin: 120
        width: 200
        height: 100
        border.width: 1
        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            text: qsTr("分")
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 20
        anchors.top: backGround.top
        anchors.topMargin: 350
        width: 200
        height: 100
        border.width: 1
        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            text: qsTr("序列号")
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 440
        anchors.top: backGround.top
        anchors.topMargin: 350
        width: 200
        height: 100
        border.width: 1
        Text {
            anchors.centerIn: parent
            font.pixelSize: 60
            font.bold: true
            text: qsTr("厂家码")
        }
    }




    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 20
        anchors.top: backGround.top
        anchors.topMargin: 240
        width: 200
        height: 100
        border.width: 1

        Text{
            id:y_text
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            visible: true
        }

        TextInput{
            id:y_input
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            maximumLength: 4
            visible: false
            text:y_text.text

            onEditingFinished: {
                y_text.text = y_input.text
                y_text.visible = true
                y_input.visible = false
            }
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                y_text.visible = false
                y_input.visible = true
                y_input.forceActiveFocus()
                y_input.selectAll()
            }
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 230
        anchors.top: backGround.top
        anchors.topMargin: 240
        width: 200
        height: 100
        border.width: 1

        Text{
            id:m_text
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            visible: true
        }

        TextInput{
            id:m_input
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            maximumLength: 2
            visible: false
            text:m_text.text

            onEditingFinished: {
                m_text.text = m_input.text
                m_text.visible = true
                m_input.visible = false
            }
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                m_text.visible = false
                m_input.visible = true
                m_input.forceActiveFocus()
                m_input.selectAll()
            }
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 440
        anchors.top: backGround.top
        anchors.topMargin: 240
        width: 200
        height: 100
        border.width: 1

        Text{
            id:d_text
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            visible: true
        }

        TextInput{
            id:d_input
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            maximumLength: 2
            visible: false
            text:d_text.text

            onEditingFinished: {
                d_text.text = d_input.text
                d_text.visible = true
                d_input.visible = false
            }
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                d_text.visible = false
                d_input.visible = true
                d_input.forceActiveFocus()
                d_input.selectAll()
            }
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 650
        anchors.top: backGround.top
        anchors.topMargin: 240
        width: 200
        height: 100
        border.width: 1

        Text{
            id:hour_text
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            visible: true
        }

        TextInput{
            id:hour_input
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            maximumLength: 2
            visible: false
            text:hour_text.text

            onEditingFinished: {
                hour_text.text = hour_input.text
                hour_text.visible = true
                hour_input.visible = false
            }
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                hour_text.visible = false
                hour_input.visible = true
                hour_input.forceActiveFocus()
                hour_input.selectAll()
            }
        }
    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 860
        anchors.top: backGround.top
        anchors.topMargin: 240
        width: 200
        height: 100
        border.width: 1

        Text{
            id:minute_text
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            visible: true
        }

        TextInput{
            id:minute_input
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            maximumLength: 2
            visible: false
            text:minute_text.text

            onEditingFinished: {
                minute_text.text = minute_input.text
                minute_text.visible = true
                minute_input.visible = false
            }
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                minute_text.visible = false
                minute_input.visible = true
                minute_input.forceActiveFocus()
                minute_input.selectAll()
            }
        }
    }


    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 230
        anchors.top: backGround.top
        anchors.topMargin: 350
        width: 200
        height: 100
        border.width: 1

        Text{
            id:xl_text
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            visible: true
        }

        TextInput{
            id:xl_input
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            maximumLength: 4
            visible: false
            text:xl_text.text

            onEditingFinished: {
                xl_text.text = xl_input.text
                xl_text.visible = true
                xl_input.visible = false
            }
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                xl_text.visible = false
                xl_input.visible = true
                xl_input.forceActiveFocus()
                xl_input.selectAll()
            }
        }
    }


    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 650
        anchors.top: backGround.top
        anchors.topMargin: 350
        width: 200
        height: 100
        border.width: 1

        Text{
            id:cj_text
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            visible: true
        }

        TextInput{
            id:cj_input
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            maximumLength: 4
            visible: false
            text:cj_text.text

            onEditingFinished: {
                cj_text.text = cj_input.text
                cj_text.visible = true
                cj_input.visible = false
            }
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                cj_text.visible = false
                cj_input.visible = true
                cj_input.forceActiveFocus()
                cj_input.selectAll()
            }
        }
    }


    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 20
        anchors.top: backGround.top
        anchors.topMargin: 480
        width: 750
        height: 100
        border.width: 1

        Text {
            anchors.centerIn: parent
            font.pixelSize: 45
            font.bold: true
            text:Cpp_Decryption.en_Result
        }
    }

    Rectangle{
        id:mode_Btn
        anchors.left: backGround.left
        anchors.leftMargin: 860
        anchors.top: backGround.top
        anchors.topMargin: 350
        width: 200
        height: 100
        border.width: 1
        color: mode_Btn.flag ? "gold" : "white"

        property bool flag: false

        Text{
            anchors.centerIn: parent
            font.pixelSize: 30
            text: parent.flag ? "全解密模式" : "日期解密模式"
        }

        MouseArea{
            anchors.fill: parent

            onClicked: {
                parent.forceActiveFocus()
                parent.flag = !parent.flag
            }


        }

    }
    Rectangle{
        anchors.left: backGround.left
        anchors.leftMargin: 780
        anchors.top: backGround.top
        anchors.topMargin: 480
        width: 270
        height: 100
        border.width: 1

        Text{
            anchors.centerIn: parent
            font.pixelSize: 50
            text:"生成密码"
        }

        MouseArea{
            anchors.fill: parent

            onPressed: {
                parent.color = "pink"
                parent.forceActiveFocus()
                if(mode_Btn.flag === true)
                {
                    Cpp_Decryption.createDecryptionCode("1",
                                                  "1",
                                                  "1",
                                                  "1",
                                                  "1",
                                                  xl_text.text,
                                                  cj_text.text)
                }
                else if(mode_Btn.flag === false)
                {
                    Cpp_Decryption.createDecryptionCode(y_text.text,
                                                  m_text.text,
                                                  d_text.text,
                                                  hour_text.text,
                                                  minute_text.text,
                                                  xl_text.text,
                                                  cj_text.text)
                }


            }
            onReleased:  {
                parent.color = "white"
            }


        }

    }

}
